#include "dispatcher.h"

namespace anb { namespace net {

dispatcher::dispatcher() {
}

dispatcher::~dispatcher() {
	clear();
}

cmd_handler::ptr dispatcher::get_cmd_handler(unsigned short cmd) {
	std::map<unsigned short, cmd_handler::ptr>::const_iterator ite = m_handlers_by_cmd.find(cmd);
	if (ite != m_handlers_by_cmd.end()) {
		return ite->second;
	}
	return NULL;
}

cmd_handler::ptr dispatcher::get_cmd_handler(const std::string& cmd) {
	std::map<std::string, cmd_handler::ptr>::const_iterator ite = m_handlers_by_name.find(cmd);
	if (ite != m_handlers_by_name.end()) {
		return ite->second;
	}
	return NULL;
}

void dispatcher::clear() {
	m_handlers.clear();
	m_handlers_by_cmd.clear();
	m_handlers_by_name.clear();
}

}
}
